// * Tree组件
<template>
  <div>
    <TreeNode
      v-for="(item, index) of cloneData"
      :key="`tree-node-${index}`"
      :data="item"
      :show-checkbox="showCheckbox"
    />
  </div>
</template>

<script>
import TreeNode from './TreeNode.vue'
import { deepClone } from '../../utils/assist'

export default {
  name: 'Tree',

  components: { TreeNode },

  props: {
    data: {
      type: Array,
      default: () => [],
    },
    showCheckbox: {
      type: Boolean,
      default: false,
    },
  },

  data() {
    return {
      cloneData: deepClone(this.data),
    }
  },

  computed: {},

  watch: {
    data() {
      this.cloneData = deepClone(this.data)
    },
  },

  created() {},

  mounted() {},

  methods: {
    emitEvent(eventName, data) {
      this.$emit(eventName, data, this.cloneData)
    },
  },
}
</script>
